TESLA CALL & PUT OPTION DATA 30 JUNE 2023¶

image-2.png

HEMANT THAPA¶

In [2]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import yfinance as yf
import mplfinance as mpf
import datetime
import warnings
warnings.filterwarnings("ignore")

LOADING DATASET¶

In [3]:
df = pd.read_csv(r'tsla_26_june.csv')
In [4]:
df.dropna(inplace=True)
In [5]:
df.columns.str.lower()
Out[5]:
Index(['symbol', 'price', 'type', 'strike', 'exp date', 'dte', 'bid',
       'midpoint', 'ask', 'last', 'volume', 'open int', 'vol/oi', 'iv',
       'delta', 'time'],
      dtype='object')
In [6]:
df[:10]
Out[6]:
Symbol Price Type Strike Exp Date DTE Bid Midpoint Ask Last Volume Open Int Vol/OI IV Delta Time
0 ZM 66.62 Call 74.0 2023-07-21 27.0 0.89 0.93 0.97 0.97 6663.0 125.0 53.30 44.80% 0.220508 2023-06-23
1 AMD 110.01 Call 109.0 2023-06-23 0.0 0.93 0.98 1.03 0.96 45668.0 938.0 48.69 9.21% 0.974842 2023-06-23
2 NWL 7.85 Call 9.0 2023-08-18 55.0 0.25 0.30 0.35 0.35 7119.0 157.0 45.34 62.68% 0.319053 2023-06-23
3 AVDL 13.51 Put 12.5 2023-09-15 83.0 1.00 1.35 1.70 1.49 10040.0 225.0 44.62 82.12% -0.338256 2023-06-23
4 SHEL 59.60 Call 65.0 2023-09-15 83.0 0.60 0.65 0.70 0.68 10002.0 237.0 42.20 20.68% 0.212815 2023-06-23
5 AMD 110.01 Call 108.0 2023-06-23 0.0 1.79 1.92 2.05 2.06 12510.0 324.0 38.61 21.64% 0.951341 2023-06-23
6 CHPT 7.36 Call 7.5 2023-06-30 6.0 0.21 0.22 0.22 0.21 11070.0 294.0 37.65 71.54% 0.440187 2023-06-23
7 CPNG 16.60 Put 16.0 2023-07-21 27.0 0.39 0.40 0.41 0.40 5437.0 146.0 37.24 38.37% -0.331888 2023-06-23
8 SPCE 4.34 Call 12.0 2023-10-20 118.0 0.31 0.33 0.36 0.35 3276.0 102.0 32.12 151.18% 0.231735 2023-06-23
9 SBUX 98.34 Put 97.0 2023-06-30 6.0 0.56 0.57 0.58 0.55 6970.0 258.0 27.02 22.62% -0.307568 2023-06-23

PRE PROCESSING TESLA PUT & CALL¶

In [7]:
tesla = df[df['Symbol']=="TSLA"]

CALL¶

In [8]:
tesla_call = tesla[tesla['Type']=="Call"]
In [12]:
tesla_call = tesla_call.sort_values('Exp Date')
tesla_call = tesla_call[tesla_call['Exp Date']=="2023-06-30"]
tesla_call
Out[12]:
Symbol Price Type Strike Exp Date DTE Bid Midpoint Ask Last Volume Open Int Vol/OI IV Delta Time
434 TSLA 256.6 Call 222.5 2023-06-30 6.0 34.35 34.63 34.90 33.25 882.0 236.0 3.74 64.75% 0.961565 2023-06-23
53 TSLA 256.6 Call 257.5 2023-06-30 6.0 7.05 7.10 7.15 7.14 27731.0 2509.0 11.05 56.91% 0.499983 2023-06-23
113 TSLA 256.6 Call 262.5 2023-06-30 6.0 5.00 5.05 5.10 5.10 31064.0 3965.0 7.83 57.33% 0.396968 2023-06-23
135 TSLA 256.6 Call 272.5 2023-06-30 6.0 2.46 2.50 2.53 2.51 12862.0 1771.0 7.26 59.38% 0.229428 2023-06-23
154 TSLA 256.6 Call 260.0 2023-06-30 6.0 5.95 6.00 6.05 6.02 64554.0 9369.0 6.89 56.84% 0.447199 2023-06-23
184 TSLA 256.6 Call 255.0 2023-06-30 6.0 8.25 8.33 8.40 8.30 27139.0 4366.0 6.22 56.27% 0.553449 2023-06-23
221 TSLA 256.6 Call 277.5 2023-06-30 6.0 1.70 1.73 1.76 1.74 7507.0 1335.0 5.62 60.65% 0.169182 2023-06-23
499 TSLA 256.6 Call 267.5 2023-06-30 6.0 3.50 3.58 3.65 3.58 10086.0 2994.0 3.37 58.10% 0.304986 2023-06-23
435 TSLA 256.6 Call 265.0 2023-06-30 6.0 4.25 4.30 4.35 4.30 38698.0 10351.0 3.74 57.83% 0.349703 2023-06-23
350 TSLA 256.6 Call 280.0 2023-06-30 6.0 1.42 1.45 1.48 1.42 33882.0 7835.0 4.32 60.96% 0.143020 2023-06-23
517 TSLA 256.6 Call 252.5 2023-06-30 6.0 9.60 9.68 9.75 9.69 3491.0 1064.0 3.28 56.37% 0.606664 2023-06-23
982 TSLA 256.6 Call 325.0 2023-06-30 6.0 0.08 0.09 0.10 0.10 4727.0 2567.0 1.84 79.03% 0.011522 2023-06-23
957 TSLA 256.6 Call 315.0 2023-06-30 6.0 0.15 0.16 0.16 0.16 5325.0 2790.0 1.91 74.63% 0.018477 2023-06-23
872 TSLA 256.6 Call 287.5 2023-06-30 6.0 0.82 0.85 0.87 0.82 3885.0 1840.0 2.11 63.22% 0.088174 2023-06-23
726 TSLA 256.6 Call 292.5 2023-06-30 6.0 0.58 0.60 0.61 0.62 2706.0 1106.0 2.45 65.34% 0.065368 2023-06-23
970 TSLA 256.6 Call 285.0 2023-06-30 6.0 0.98 1.00 1.01 1.01 10316.0 5488.0 1.88 62.89% 0.105417 2023-06-23
555 TSLA 256.6 Call 275.0 2023-06-30 6.0 2.08 2.09 2.10 2.10 29527.0 9582.0 3.08 60.10% 0.197814 2023-06-23
550 TSLA 256.6 Call 270.0 2023-06-30 6.0 2.96 2.98 3.00 2.99 39882.0 12904.0 3.09 58.62% 0.264798 2023-06-23
599 TSLA 256.6 Call 282.5 2023-06-30 6.0 1.18 1.21 1.23 1.21 6679.0 2284.0 2.92 62.12% 0.123620 2023-06-23
In [13]:
tesla_call.columns
Out[13]:
Index(['Symbol', 'Price', 'Type', 'Strike', 'Exp Date', 'DTE', 'Bid',
       'Midpoint', 'Ask', 'Last', 'Volume', 'Open Int', 'Vol/OI', 'IV',
       'Delta', 'Time'],
      dtype='object')
In [14]:
bin_width = 5
plt.bar(tesla_call['Strike'], tesla_call['Open Int'], width=bin_width)
plt.xlabel('Strike')
plt.ylabel('Open Int')
plt.title('Open Interest by Strike')
plt.grid(linestyle="--", alpha=0.4, color="grey")
plt.show()
In [15]:
bin_width = 5
plt.bar(tesla_call['Strike'], tesla_call['Open Int'], width=bin_width)
highest_open_interest_index = tesla_call['Open Int'].idxmax()
highest_strike = tesla_call.loc[highest_open_interest_index, 'Strike']
highest_open_interest = tesla_call.loc[highest_open_interest_index, 'Open Int']
plt.annotate(f"Highest: {highest_strike}\nOpen Int: {highest_open_interest}",
             xy=(highest_strike, highest_open_interest),
             xytext=(highest_strike + 10, highest_open_interest),
             arrowprops=dict(facecolor='black', arrowstyle='->'))
plt.xlabel('Strike')
plt.ylabel('Open Int')
plt.title('Open Interest by Strike')
plt.grid(linestyle="--", alpha=0.4, color="grey")
plt.show()
In [16]:
tesla_call.describe()
Out[16]:
Price Strike DTE Bid Midpoint Ask Last Volume Open Int Vol/OI Delta
count 19.0 19.000000 19.0 19.000000 19.000000 19.000000 19.000000 19.000000 19.000000 19.000000 19.000000
mean 256.6 273.947368 6.0 4.861053 4.912105 4.957895 4.845263 18997.000000 4439.789474 4.347368 0.291439
std 0.0 22.689262 0.0 7.670406 7.729002 7.786653 7.435280 17399.643212 3731.097747 2.495638 0.242430
min 256.6 222.500000 6.0 0.080000 0.090000 0.100000 0.100000 882.000000 236.000000 1.840000 0.011522
25% 256.6 261.250000 6.0 1.080000 1.105000 1.120000 1.110000 5026.000000 1805.500000 2.685000 0.114518
50% 256.6 272.500000 6.0 2.460000 2.500000 2.530000 2.510000 10316.000000 2790.000000 3.370000 0.229428
75% 256.6 283.750000 6.0 5.475000 5.525000 5.575000 5.560000 30295.500000 6661.500000 5.920000 0.422084
max 256.6 325.000000 6.0 34.350000 34.630000 34.900000 33.250000 64554.000000 12904.000000 11.050000 0.961565

PUT¶

In [17]:
tesla_put = tesla[tesla['Type']=="Put"]
In [18]:
tesla_put = tesla_put[tesla_put['Exp Date']=="2023-06-30"]
tesla_put
Out[18]:
Symbol Price Type Strike Exp Date DTE Bid Midpoint Ask Last Volume Open Int Vol/OI IV Delta Time
128 TSLA 256.6 Put 257.5 2023-06-30 6.0 7.70 7.80 7.90 7.70 18042.0 2420.0 7.46 55.85% -0.501608 2023-06-23
211 TSLA 256.6 Put 255.0 2023-06-30 6.0 6.45 6.53 6.60 6.45 38527.0 6709.0 5.74 55.90% -0.447248 2023-06-23
238 TSLA 256.6 Put 252.5 2023-06-30 6.0 5.30 5.38 5.45 5.45 10702.0 1968.0 5.44 56.85% -0.394735 2023-06-23
250 TSLA 256.6 Put 245.0 2023-06-30 6.0 2.80 2.84 2.88 2.84 22573.0 4330.0 5.21 56.65% -0.247173 2023-06-23
356 TSLA 256.6 Put 250.0 2023-06-30 6.0 4.35 4.40 4.45 4.45 44351.0 10360.0 4.28 56.77% -0.343027 2023-06-23
387 TSLA 256.6 Put 260.0 2023-06-30 6.0 9.15 9.23 9.30 9.20 25869.0 6400.0 4.04 56.69% -0.554204 2023-06-23
554 TSLA 256.6 Put 240.0 2023-06-30 6.0 1.74 1.76 1.78 1.78 28843.0 9374.0 3.08 57.53% -0.170078 2023-06-23
691 TSLA 256.6 Put 232.5 2023-06-30 6.0 0.82 0.85 0.87 0.87 5086.0 1998.0 2.55 60.02% -0.091714 2023-06-23
696 TSLA 256.6 Put 247.5 2023-06-30 6.0 3.50 3.55 3.60 3.58 9723.0 3839.0 2.53 56.69% -0.293518 2023-06-23
771 TSLA 256.6 Put 237.5 2023-06-30 6.0 1.36 1.39 1.42 1.38 4943.0 2122.0 2.33 57.91% -0.138016 2023-06-23
843 TSLA 256.6 Put 227.5 2023-06-30 6.0 0.51 0.53 0.54 0.53 2870.0 1325.0 2.17 61.94% -0.058763 2023-06-23
869 TSLA 256.6 Put 262.5 2023-06-30 6.0 10.70 10.80 10.90 10.77 6388.0 3007.0 2.12 57.08% -0.604903 2023-06-23
913 TSLA 256.6 Put 242.5 2023-06-30 6.0 2.22 2.26 2.29 2.29 6451.0 3216.0 2.01 57.40% -0.207533 2023-06-23
923 TSLA 256.6 Put 230.0 2023-06-30 6.0 0.65 0.67 0.68 0.66 14529.0 7339.0 1.98 60.51% -0.072238 2023-06-23
In [19]:
bin_width = 5
plt.bar(tesla_put['Strike'], tesla_put['Open Int'], width=bin_width)
plt.xlabel('Strike')
plt.ylabel('Open Int')
plt.title('Open Interest by Strike')
plt.grid(linestyle="--", alpha=0.4, color="grey")
plt.show()
In [20]:
bin_width = 5
plt.bar(tesla_put['Strike'], tesla_put['Open Int'], width=bin_width)
highest_open_interest_index = tesla_put['Open Int'].idxmax()
highest_strike = tesla_put.loc[highest_open_interest_index, 'Strike']
highest_open_interest = tesla_put.loc[highest_open_interest_index, 'Open Int']
plt.annotate(f"Highest: {highest_strike}\nOpen Int: {highest_open_interest}",
             xy=(highest_strike, highest_open_interest),
             xytext=(highest_strike + 10, highest_open_interest),
             arrowprops=dict(facecolor='black', arrowstyle='->'))
plt.xlabel('Strike')
plt.ylabel('Open Int')
plt.title('Open Interest by Strike')
plt.grid(linestyle="--", alpha=0.4, color="grey")
plt.show()
In [21]:
tesla_put.describe()
Out[21]:
Price Strike DTE Bid Midpoint Ask Last Volume Open Int Vol/OI Delta
count 1.400000e+01 14.000000 14.0 14.000000 14.000000 14.000000 14.000000 14.000000 14.000000 14.000000 14.000000
mean 2.566000e+02 245.714286 6.0 4.089286 4.142143 4.190000 4.139286 17064.071429 4600.500000 3.638571 -0.294626
std 5.898920e-14 11.241602 0.0 3.319598 3.347479 3.376204 3.326249 13220.276457 2929.690683 1.745556 0.183615
min 2.566000e+02 227.500000 6.0 0.510000 0.530000 0.540000 0.530000 2870.000000 1325.000000 1.980000 -0.604903
25% 2.566000e+02 238.125000 6.0 1.455000 1.482500 1.510000 1.480000 6403.750000 2196.500000 2.210000 -0.434120
50% 2.566000e+02 246.250000 6.0 3.150000 3.195000 3.240000 3.210000 12615.500000 3527.500000 2.815000 -0.270346
75% 2.566000e+02 254.375000 6.0 6.162500 6.242500 6.312500 6.200000 25045.000000 6631.750000 4.977500 -0.146032
max 2.566000e+02 262.500000 6.0 10.700000 10.800000 10.900000 10.770000 44351.000000 10360.000000 7.460000 -0.058763

CALL & PUT OPEN INTEREST COMPARISION¶

In [22]:
bin_width = 5
plt.bar(tesla_call['Strike'], tesla_call['Open Int'], width=bin_width, color="red", alpha=0.5, label="Call")
plt.bar(tesla_put['Strike'], tesla_put['Open Int'], width=bin_width, label="Put")

highest_open_interest_index = tesla_put['Open Int'].idxmax()
highest_strike = tesla_put.loc[highest_open_interest_index, 'Strike']
highest_open_interest = tesla_put.loc[highest_open_interest_index, 'Open Int']
plt.annotate(f"Highest: {highest_strike}\nOpen Int: {highest_open_interest}",
             xy=(highest_strike, highest_open_interest),
             xytext=(highest_strike + 10, highest_open_interest),
             arrowprops=dict(facecolor='black', arrowstyle='->'))
highest_open_interest_index = tesla_call['Open Int'].idxmax()
highest_strike = tesla_call.loc[highest_open_interest_index, 'Strike']
highest_open_interest = tesla_call.loc[highest_open_interest_index, 'Open Int']
plt.annotate(f"Highest: {highest_strike}\nOpen Int: {highest_open_interest}",
             xy=(highest_strike, highest_open_interest),
             xytext=(highest_strike + 10, highest_open_interest),
             arrowprops=dict(facecolor='black', arrowstyle='->'))

plt.xlabel('Strike')
plt.ylabel('Open Int')
plt.title('Open Interest by Strike')
plt.legend()
plt.grid(linestyle="--", alpha=0.4, color="grey")
plt.show()
In [23]:
bin_width = 5
plt.bar(tesla_call['Strike'], tesla_call['Open Int'], width=bin_width, color="red", alpha=0.5, label="Call")
plt.bar(tesla_put['Strike'], tesla_put['Open Int'], width=bin_width, label="Put")

highest_open_interest_indices = tesla_call['Open Int'].nlargest(3).index
for index in highest_open_interest_indices:
    strike = tesla_call.loc[index, 'Strike']
    open_interest = tesla_call.loc[index, 'Open Int']
    plt.annotate(f"Highest: {strike}\nOpen Int: {open_interest}",
                 xy=(strike, open_interest),
                 xytext=(strike + 10, open_interest),
                 arrowprops=dict(facecolor='black', arrowstyle='->'))

highest_open_interest_indices = tesla_put['Open Int'].nlargest(3).index
for index in highest_open_interest_indices:
    strike = tesla_put.loc[index, 'Strike']
    open_interest = tesla_put.loc[index, 'Open Int']
    plt.annotate(f"Highest: {strike}\nOpen Int: {open_interest}",
                 xy=(strike, open_interest),
                 xytext=(strike + 10, open_interest),
                 arrowprops=dict(facecolor='black', arrowstyle='->'))
plt.xlabel('Strike')
plt.ylabel('Open Int')
plt.title('Open Interest by Strike')
plt.legend()
plt.grid(linestyle="--", alpha=0.4, color="grey")
plt.show()

21.06. 2023¶

In [24]:
stock_symbol = 'TSLA'
stock_data = yf.download(stock_symbol, interval='1m', period='1d')
[*********************100%***********************]  1 of 1 completed
In [25]:
stock_data.to_csv('Tesla_30_june.csv')
In [26]:
fig, axes = mpf.plot(stock_data, 
                     type='candle', 
                     figratio=(20, 6)
                     ,style='yahoo', 
                     title=stock_symbol, 
                     returnfig=True)
axes[0].set_xlabel('Time', fontsize=12)
axes[0].set_ylabel('Price', fontsize=12)
plt.show()
In [27]:
stock_symbol = 'TSLA'
stock_data = yf.download(stock_symbol, interval='5m', period='10d')
[*********************100%***********************]  1 of 1 completed

200 EXPONENTIAL MOVING AVERAGES¶

In [28]:
stock_data['EMA_200'] = stock_data['Close'].ewm(span=200, adjust=False).mean()
In [29]:
EMA_200 = mpf.make_addplot(stock_data['EMA_200'], color='red', width=1)
mpf.plot(stock_data, type='candle', addplot=[EMA_200], figratio=(15, 6), style='yahoo', title=stock_symbol)
In [30]:
tesla_call.columns
Out[30]:
Index(['Symbol', 'Price', 'Type', 'Strike', 'Exp Date', 'DTE', 'Bid',
       'Midpoint', 'Ask', 'Last', 'Volume', 'Open Int', 'Vol/OI', 'IV',
       'Delta', 'Time'],
      dtype='object')
In [31]:
tesla_call_open = {'Strike':tesla_call['Strike'], 'Open Interest':tesla_call['Open Int']}
tesla_put_open = {'Strike':tesla_put['Strike'], 'Open Interest':tesla_put['Open Int']}
In [32]:
df_call_open = pd.DataFrame(tesla_call_open)
df_call_open.sort_values('Open Interest', ascending=False)
Out[32]:
Strike Open Interest
550 270.0 12904.0
435 265.0 10351.0
555 275.0 9582.0
154 260.0 9369.0
350 280.0 7835.0
970 285.0 5488.0
184 255.0 4366.0
113 262.5 3965.0
499 267.5 2994.0
957 315.0 2790.0
982 325.0 2567.0
53 257.5 2509.0
599 282.5 2284.0
872 287.5 1840.0
135 272.5 1771.0
221 277.5 1335.0
726 292.5 1106.0
517 252.5 1064.0
434 222.5 236.0
In [33]:
df_put_open = pd.DataFrame(tesla_put_open)
df_put_open.sort_values('Open Interest', ascending=False)
Out[33]:
Strike Open Interest
356 250.0 10360.0
554 240.0 9374.0
923 230.0 7339.0
211 255.0 6709.0
387 260.0 6400.0
250 245.0 4330.0
696 247.5 3839.0
913 242.5 3216.0
869 262.5 3007.0
128 257.5 2420.0
771 237.5 2122.0
691 232.5 1998.0
238 252.5 1968.0
843 227.5 1325.0

OPEN INTEREST WITH RESPECT TO POINT¶

In [34]:
bin_width = 10
df_call_open['Bin'] = (df_call_open['Strike'] // bin_width) * bin_width
sum_data = df_call_open.groupby('Bin')['Open Interest'].sum()
print(sum_data)
Bin
220.0      236.0
250.0     7939.0
260.0    26679.0
270.0    25592.0
280.0    17447.0
290.0     1106.0
310.0     2790.0
320.0     2567.0
Name: Open Interest, dtype: float64
In [35]:
bin_width = 20
df_call_open['Bin'] = (df_call_open['Strike'] // bin_width) * bin_width
sum_data = df_call_open.groupby('Bin')['Open Interest'].sum()
print(sum_data)
Bin
220.0      236.0
240.0     7939.0
260.0    52271.0
280.0    18553.0
300.0     2790.0
320.0     2567.0
Name: Open Interest, dtype: float64
In [36]:
bin_width = 30
df_call_open['Bin'] = (df_call_open['Strike'] // bin_width) * bin_width
sum_data = df_call_open.groupby('Bin')['Open Interest'].sum()
print(sum_data)
Bin
210.0      236.0
240.0    34618.0
270.0    44145.0
300.0     5357.0
Name: Open Interest, dtype: float64
In [37]:
bin_width = 40
df_call_open['Bin'] = (df_call_open['Strike'] // bin_width) * bin_width
sum_data = df_call_open.groupby('Bin')['Open Interest'].sum()
print(sum_data)
Bin
200.0      236.0
240.0    60210.0
280.0    21343.0
320.0     2567.0
Name: Open Interest, dtype: float64
In [38]:
bin_width = 50
df_call_open['Bin'] = (df_call_open['Strike'] // bin_width) * bin_width
sum_data = df_call_open.groupby('Bin')['Open Interest'].sum()
print(sum_data)
Bin
200.0      236.0
250.0    78763.0
300.0     5357.0
Name: Open Interest, dtype: float64
In [39]:
bin_width = 100
df_call_open['Bin'] = (df_call_open['Strike'] // bin_width) * bin_width
sum_data = df_call_open.groupby('Bin')['Open Interest'].sum()
print(sum_data)
Bin
200.0    78999.0
300.0     5357.0
Name: Open Interest, dtype: float64
In [40]:
#Data Validation
above_300 = df_call_open[df_call_open['Strike']>=300]
above_300['Open Interest'].sum()
Out[40]:
5357.0

CALL PRICE CHART¶

Call option is typically used to bet on a long or higher price trend in the underlying asset. When you purchase a call option, you are anticipating that the price of the underlying asset will increase. If the price does rise above the strike price, the call option becomes valuable, as it allows you to buy the asset at a lower price and potentially profit from the price difference.

In [41]:
bin_width = 10
df_call_open['Bin'] = (df_call_open['Strike'] // bin_width) * bin_width
sum_data = df_call_open.groupby('Bin')['Open Interest'].sum()
print(sum_data)
Bin
220.0      236.0
250.0     7939.0
260.0    26679.0
270.0    25592.0
280.0    17447.0
290.0     1106.0
310.0     2790.0
320.0     2567.0
Name: Open Interest, dtype: float64
In [42]:
bin_values = [x for x in sum_data.index]
open_interest = [x for x in sum_data.values]
In [43]:
bin_values
Out[43]:
[220.0, 250.0, 260.0, 270.0, 280.0, 290.0, 310.0, 320.0]
In [44]:
open_interest
Out[44]:
[236.0, 7939.0, 26679.0, 25592.0, 17447.0, 1106.0, 2790.0, 2567.0]
In [45]:
stock_symbol = 'TSLA'
stock_data = yf.download(stock_symbol, interval="5m",period='30d')
plt.figure(figsize=(15,6))
stock_data.Close.plot();
[*********************100%***********************]  1 of 1 completed
In [46]:
plt.figure(figsize=(15, 6))
stock_data['Close'].plot()
stock_data['Open'].plot()
for bin_value in bin_values:
    plt.axhline(y=bin_value, color='r', linestyle='--')
plt.xlabel('Date')
plt.ylabel('Close Price')
plt.legend()
plt.title(f'{stock_symbol} Price with Horizontal Lines and Open Interest Labels')
plt.show()
In [47]:
plt.figure(figsize=(15, 6))
stock_data['Close'].plot()
stock_data['Open'].plot()
for bin_value in bin_values:
    plt.axhline(y=bin_value, color='r', linestyle='--')
for i in range(len(bin_values)):
    plt.text(stock_data.index[0], bin_values[i], str(open_interest[i]), color='b')
plt.xlabel('Date')
plt.ylabel('Close Price')
plt.legend()
plt.title(f'{stock_symbol} Price with Horizontal Lines and Open Interest Labels')
plt.show()
In [48]:
stock_data['EMA_200'] = stock_data['Close'].ewm(span=200, adjust=False).mean()
In [49]:
fig, ax = plt.subplots(figsize=(15, 6))
ax.plot(stock_data.index, stock_data['Close'], label='Close')
ax.plot(stock_data.index, stock_data['EMA_200'], color='red', label='EMA 200')
for bin_value in bin_values:
    ax.axhline(y=bin_value, color='r', linestyle='--')
for i in range(len(bin_values)):
    ax.text(stock_data.index[0], bin_values[i], str(open_interest[i]), color='b')
ax.set_xlabel('Date')
ax.set_ylabel('Price')
ax.set_title(f'{stock_symbol} Price with Horizontal Lines and Open Interest Labels')
ax.legend()
plt.show()

PUT PRICE CHART¶

A put option can be used as a strategy to bet on a downward movement or a decline in the price of the underlying asset. By purchasing a put option, the holder has the right, but not the obligation, to sell the underlying asset at the strike price within a specific time period.

If the price of the underlying asset decreases below the strike price, the put option can be profitable. The holder can exercise the put option and sell the asset at a higher strike price, thereby benefiting from the price decline. This makes put options popular for traders and investors who anticipate a bearish or downward market trend.

In [50]:
bin_width = 5
df_put_open['Bin'] = (df_put_open['Strike'] // bin_width) * bin_width
sum_data = df_put_open.groupby('Bin')['Open Interest'].sum()
print(sum_data)
Bin
225.0     1325.0
230.0     9337.0
235.0     2122.0
240.0    12590.0
245.0     8169.0
250.0    12328.0
255.0     9129.0
260.0     9407.0
Name: Open Interest, dtype: float64
In [51]:
bin_width = 10
df_put_open['Bin'] = (df_put_open['Strike'] // bin_width) * bin_width
sum_data = df_put_open.groupby('Bin')['Open Interest'].sum()
print(sum_data)
Bin
220.0     1325.0
230.0    11459.0
240.0    20759.0
250.0    21457.0
260.0     9407.0
Name: Open Interest, dtype: float64
In [52]:
bin_values = [x for x in sum_data.index]
open_interest = [x for x in sum_data.values]
In [53]:
sum_data
Out[53]:
Bin
220.0     1325.0
230.0    11459.0
240.0    20759.0
250.0    21457.0
260.0     9407.0
Name: Open Interest, dtype: float64
In [54]:
plt.figure(figsize=(15, 6))
stock_data['Close'].plot()
stock_data['Open'].plot()
for bin_value in bin_values:
    plt.axhline(y=bin_value, color='r', linestyle='--')
for i in range(len(bin_values)):
    plt.text(stock_data.index[0], bin_values[i], str(open_interest[i]), color='b')
plt.xlabel('Date')
plt.ylabel('Close Price')
plt.legend()
plt.title(f'{stock_symbol} Price with Horizontal Lines and Open Interest Labels')
plt.show()
In [55]:
stock_data['EMA_200'] = stock_data['Close'].ewm(span=200, adjust=False).mean()
In [56]:
fig, ax = plt.subplots(figsize=(15, 6))
ax.plot(stock_data.index, stock_data['Close'], label='Close')
ax.plot(stock_data.index, stock_data['EMA_200'], color='red', label='EMA 200')
for bin_value in bin_values:
    ax.axhline(y=bin_value, color='r', linestyle='--')
for i in range(len(bin_values)):
    ax.text(stock_data.index[0], bin_values[i], str(open_interest[i]), color='b')
ax.set_xlabel('Date')
ax.set_ylabel('Price')
ax.set_title(f'{stock_symbol} Price with Horizontal Lines and Open Interest Labels')
ax.legend()
plt.show()